#!/usr/bin/env ruby
require 'rubygems'
require "daemons"
require 'yaml'
require 'erb'

file_name = File.dirname(__FILE__) + "/../../vendor/rails/activesupport/lib/active_support.rb"

if(File.exists?(file_name))
  require file_name
else
rails_version = File.new(File.dirname(__FILE__)+ "/../../config/environment.rb").read.scan(/^ *RAILS_GEM_VERSION.*=.*['|"](.*)['|"]/)[0].to_s

gem 'activesupport', rails_version
require 'active_support'
end

options = YAML.load(
  ERB.new(
  IO.read(
  File.dirname(__FILE__) + "/../../config/daemons.yml"
  )).result).with_indifferent_access
options[:dir_mode] = options[:dir_mode].to_sym

Daemons.run File.dirname(__FILE__) + '/gera_historico.rb', options
